package com.tsystems.java.school.hometask;

import java.io.FileNotFoundException;
import java.util.Scanner;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

/**
 * @author sivkov evgeny
 */


public class EntranceSchoolTask  {
	
	/**
	 * The main method
	 * @param args[0] - name of the input file, args[1] - path to the output file
	 */
	public static void main(String[] args) {
		
		String[] newArgs = new String[2];
		System.out.println("enter input file");
		Scanner in = new Scanner(System.in);
		newArgs[0] = in.next();
		System.out.println("enter output file");
		newArgs[1] = in.next();
		in.close();
		
		logger = Logger.getLogger(EntranceSchoolTask.class);
		PropertyConfigurator.configure("conf/PropertyFile2.properties");
		
		/*
		if (args.length != 2) {
			
			System.out.println("incorrect input!\n Target file to be scanned is the first argument,\n path to the output files is the second argument.\n For example:\n java -jar  EntranceTask.jar E:\\EntranceTask\\test.txt E:\\EntranceTask ");
			logger.error("incorrect input. Number of parameters = " + args.length);
			System.exit(0);
		}
		*/
		
		DataStorage storage = new DataStorage();
		
		try {
			
			storage.readData(newArgs[0]);
		}
		catch(FileNotFoundException exception) {
			
			logger.error("Incorrect input! File " + newArgs[0] + " doesn't exist.", exception);
			System.out.println("Incorrect input! File " + newArgs[0] + " doesn't exist.");
		}
		
		try {
			
			storage.writeData(newArgs[1]);
		}
		catch(FileNotFoundException exception) {
			
			logger.error("Incorrect input! Path " + newArgs[1] + " is wrong.", exception);
			System.out.println("Incorrect input! Path " + newArgs[1] + " is wrong.");
		}
		
	}
	
	private static Logger logger;
}
